﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using MotoreDataBase;

namespace MvcSite.Models
{
    [Nome("users")]

    [NonQuery("SelectNotId", "SELECT * FROM Users WHERE username <> @id")]
    [NonQuery("GetUtentiIscritti", "SELECT username, password, email, tipo, stato FROM Corso_Utente INNER JOIN Users ON Corso_Utente.Id_Utente = Users.Username WHERE id_corso = @idcorso")]
    public class User
    {
        [Nome("username")]
        public string Username { get; set; }
        [Nome("password")]
        public string Password { get; set; }
        [Nome("email")]
        public string Email { get; set; }
        [Nome("tipo")]
        public UserType Tipo { get; set; }
        [Nome("stato")]
        public StatoReg Stato { get; set; }

        public User()
        {}

        public User(string Username, string Password, string Email, UserType Tipo, StatoReg Stato)
        {
            this.Username = Username;
            this.Password = Password;
            this.Email = Email;
            this.Tipo = Tipo;
            this.Stato = Stato;
        }

        public User(SqlDataReader reader)
        {
            this.Username = reader["username"].ToString();
            this.Password = reader["password"].ToString();
            this.Email = reader["email"].ToString();
            try
            {
                this.Tipo = (UserType)int.Parse(reader["tipo"].ToString());
                this.Stato = (StatoReg)int.Parse(reader["stato"].ToString());
            }
            catch (Exception ex)
            { }
        }
    }

    
    public enum UserType
    {
        User,
        Admin
    }

    public enum StatoReg
    {
        Attesa,
        Bannato,
        Confermato
    }
}